﻿using GFE.Webpart.Sample.ViewModels;
using GFE.Webpart.Sample.Views.Interfaces;
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

namespace GFE.Webpart.Sample.ControlTemplates.GFE.Webpart.Sample
{
    public partial class CustomerListControl : UserControl, ICustomerListView
    {
        public CustomerListViewModelItem currentItem;
        
        
        public ViewModels.CustomerListViewModel Model { get; set; }


        protected void Page_Load(object sender, EventArgs e)
        {
            InvokeLoadModel();
            InvokeGetCustomerList();

            ux_CustomerListControlRepeater.DataSource = Model.CustomerList;
            ux_CustomerListControlRepeater.DataBind();
            ux_CustomerListControlRepeater.ItemDataBound += ux_CustomerListControlRepeater_ItemDataBound;

        }

        void ux_CustomerListControlRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            // ...
            // ...
            // ...
        }

        public new void Init()
        {

        }

        public event EventHandler OnLoadModel;
        public void InvokeLoadModel()
        {
            var handler = OnLoadModel;
            if (handler != null) handler(this, null);
        }

        public event EventHandler OnGetCustomerList;
        public void InvokeGetCustomerList()
        {
            var handler = OnGetCustomerList;
            if (handler != null) handler(this, null);
        }
    }
}
